package com.contract.spirit.ui.exchange.bind

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.contract.commonlib.base.BaseViewModel
import com.contract.commonlib.http.ext.request
import com.contract.commonlib.http.status.ResultState
import com.contract.spirit.config.ExchangeType
import com.contract.spirit.func.net.rxApi

/**
 * @author: zhengjun
 * created: 2021/9/26
 * desc:
 */
class BindExchangeViewModel : BaseViewModel() {
    var keyValue = ObservableField<String>()
    var secretValue = ObservableField<String>()
    var passpraseValue = ObservableField<String>()
    var exchangeType: String? = null
    var bindResponse = MutableLiveData<ResultState<String>>()

    fun isOkex(): Boolean {
        return ExchangeType.OKEX == exchangeType
    }

    fun bindApi() {
        request(
            {
                rxApi
                    .bindAPI(
                        exchangeType!!,
                        keyValue.get().toString(),
                        secretValue.get().toString(),
                        passpraseValue.get().toString()
                    )
            },
            bindResponse,
            isShowDialog = true,
            loadingMessage = true
        )
    }
}